gtk4-encode-symbolic: Add debug output
authorMatthias Clasen <mclasen@redhat.com>
Wed, 30 Dec 2020 02:22:16 +0000 (21:22 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Wed, 30 Dec 2020 02:30:52 +0000 (21:30 -0500)
Add a --debug option that makes this tool produce
some debug output that can be helpful in tracking
down why symbolic svgs are broken.

docs/reference/gtk/gtk4-encode-symbolic-svg.xml
gtk/gdkpixbufutilsprivate.h
gtk/tools/encodesymbolic.c
gtk/tools/gdkpixbufutils.c

index 230f4af6d774ffe9213e5812e497998bd2f2db5e..330795bc92f48148d79e7d2ccec2f14f3596ff02 100644 (file)
     <listitem><para>Write png files to <replaceable>DIRECTORY</replaceable>
          instead of the current working directory.</para></listitem>
   </varlistentry>
+  <varlistentry>
+    <term>--debug</term>
+    <listitem><para>Generate png files of the various channels during
+         the conversion. If these files are not monochrome green, they
+         are often helpful in pinpointing the problematic parts of
+         the source svg.</para></listitem>
+  </varlistentry>
 </variablelist>
 </refsect1>
 
index 73e1c79e96f777be07095da639dcffef081d3ba1..703a550c381ce71d041dcc3cbd41b1cd1fc7987c 100644 (file)
@@ -63,6 +63,7 @@ GdkPixbuf *gtk_make_symbolic_pixbuf_from_data     (const char    *data,
                                                    int            width,
                                                    int            height,
                                                    double         scale,
+                                                   const char    *debug_output_to,
                                                    GError       **error);
 GdkPixbuf *gtk_make_symbolic_pixbuf_from_file     (GFile         *file,
                                                    int            width,
index 3bca80100d2350066b8daa460c904524ddd6913b..6f4a44f5737e406c0c9516de9678375645befa11 100644 (file)
 
 static char *output_dir = NULL;
 
+static gboolean debug;
+
 static GOptionEntry args[] = {
   { "output", 'o', 0, G_OPTION_ARG_FILENAME, &output_dir, N_("Output to this directory instead of cwd"), NULL },
+  { "debug", 0, 0, G_OPTION_ARG_NONE, &debug, N_("Generate debug output") },
   { NULL }
 };
 
@@ -65,7 +68,7 @@ main (int argc, char **argv)
 
   g_set_prgname ("gtk-encode-symbolic-svg");
 
-  context = g_option_context_new ("PATH WIDTHxHEIGHT");
+  context = g_option_context_new ("[OPTION…] PATH WIDTHxHEIGHT");
   g_option_context_add_main_entries (context, args, GETTEXT_PACKAGE);
 
   g_option_context_parse (context, &argc, &argv, NULL);
@@ -104,7 +107,9 @@ main (int argc, char **argv)
       return 1;
     }
 
-  symbolic = gtk_make_symbolic_pixbuf_from_data (data, len, width, height, 1.0, &error);
+  basename = g_path_get_basename (path);
+
+  symbolic = gtk_make_symbolic_pixbuf_from_data (data, len, width, height, 1.0, debug ? basename : NULL, &error);
   if (symbolic == NULL)
     {
       g_printerr (_("Can’t load file: %s\n"), error->message);
@@ -113,8 +118,6 @@ main (int argc, char **argv)
 
   g_free (data);
 
-  basename = g_path_get_basename (path);
-
   dot = strrchr (basename, '.');
   if (dot != NULL)
     *dot = 0;
index 09802f5ef83fd641d1dbf8e0e87045171a76e35c..66a4cc46de02c01ef31affb59ce4cdf8ae3d9af5 100644 (file)
@@ -429,6 +429,7 @@ gtk_make_symbolic_pixbuf_from_data (const char  *file_data,
                                     int          width,
                                     int          height,
                                     double       scale,
+                                    const char  *debug_output_basename,
                                     GError     **error)
 
 {
@@ -491,6 +492,16 @@ gtk_make_symbolic_pixbuf_from_data (const char  *file_data,
       if (loaded == NULL)
         goto out;
 
+      if (debug_output_basename)
+        {
+          char *filename;
+
+          filename = g_strdup_printf ("%s.debug%d.png", debug_output_basename, plane);
+          g_print ("Writing %s\n", filename);
+          gdk_pixbuf_save (loaded, filename, "png", NULL, NULL);
+          g_free (filename);
+        }
+
       if (pixbuf == NULL)
         {
           pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8,
@@ -534,7 +545,7 @@ gtk_make_symbolic_pixbuf_from_resource (const char  *path,
 
   data = g_bytes_get_data (bytes, &size);
 
-  pixbuf = gtk_make_symbolic_pixbuf_from_data (data, size, width, height, scale, error);
+  pixbuf = gtk_make_symbolic_pixbuf_from_data (data, size, width, height, scale, NULL, error);
 
   g_bytes_unref (bytes);
 
@@ -555,7 +566,7 @@ gtk_make_symbolic_pixbuf_from_path (const char  *path,
   if (!g_file_get_contents (path, &data, &size, error))
     return NULL;
 
-  pixbuf = gtk_make_symbolic_pixbuf_from_data (data, size, width, height, scale, error);
+  pixbuf = gtk_make_symbolic_pixbuf_from_data (data, size, width, height, scale, NULL, error);
 
   g_free (data);
 
@@ -576,7 +587,7 @@ gtk_make_symbolic_pixbuf_from_file (GFile       *file,
   if (!g_file_load_contents (file, NULL, &data, &size, NULL, error))
     return NULL;
 
-  pixbuf = gtk_make_symbolic_pixbuf_from_data (data, size, width, height, scale, error);
+  pixbuf = gtk_make_symbolic_pixbuf_from_data (data, size, width, height, scale, NULL, error);
 
   g_free (data);